import React, { Component } from "react";

import { Link, Route, Switch, Redirect } from "react-router-dom";

class Home extends Component {
  render() {
    return <div>这是home页面</div>;
  }
}
class About extends Component {
  render() {
    return <div>这是about页面</div>;
  }
}

class NotFound extends Component {
  render() {
    return <div>404 not found...</div>;
  }
}

class App extends Component {
  render() {
    return (
      <>
        <h2>react-router-v5-404页面</h2>
        <ul>
          <li>
            <Link to="/home">首页</Link>
          </li>
          <li>
            <Link to="/about">关于页</Link>
          </li>
        </ul>

        <Switch>
          <Redirect from="/" to="/home" exact></Redirect>
          <Route path="/home" component={Home}></Route>
          <Route path="/about" component={About}></Route>
          {/* path="*" */}
          {/* 必须配合Switch */}
          {/* 只能写在最后 */}
          <Route path="*" component={NotFound}></Route>
        </Switch>
      </>
    );
  }
}

export default App;
